from pydantic import BaseModel, Field, field_validator
import typing as T
from datetime import date


class PageParam(BaseModel):
    """
    用来接收员工分页查询的参数
    """

    name: str | None = Field(None, description="员工名称用以模糊查询")
    gender: int | None = Field(None, description="员工性别")
    begin: date | None = Field(None, description="入职日期开始")
    end: date | None = Field(None, description="入职日期结束")
    page: int | None = Field(1, description="当前页码")
    pageSize: int | None = Field(10, description="每页条数")

    @field_validator("name", mode="before")
    def validate_name(cls, v):
        if v == "":
            return None
        return v

    @field_validator("begin", "end", mode="before")
    def validate_date(cls, v):
        if v == "":
            return None
        return v

    @field_validator("gender", mode="before")
    def validate_gender(cls, v):
        if v == "":
            return None
        return v
